package com.cxx.service.ServiceImpl;

import com.cxx.mapper.UserMapper;
import com.cxx.pojo.Admin;
import com.cxx.pojo.User;
import com.cxx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    //用户注册方法，当已经有此账户返回0;当注册失败返回-1;当注册成功返回1
    @Override
    public Integer regist(User user) {
        if (userMapper.select(user.getUserName())||userMapper.selectAdmin(user.getUserName())) {
            return 0;
        }else{
            userMapper.regist(user);
        }
        if(userMapper.select(user.getUserName())){
            return  1;
        }
        return -1;
    }

    @Override
    public User exist(String userName, String userPassword) {

        return userMapper.exist(userName,userPassword);
    }

    @Override
    public Admin adminExist(String userName, String userPassword) {
        return userMapper.adminExist(userName,userPassword);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public void updateAdmin(Admin admin) {
        userMapper.updateAdmin(admin);
    }
}